package com.qianbao.qianbaobusiness.ui.mine;

import com.androidbase.base.mvp.RxMvpPresenter;
import com.androidbase.utils.RxUtils;
import com.baseandroid.config.ContractApi;
import com.baseandroid.config.Global;
import com.baseandroid.config.MyApi;
import com.baseandroid.retrofit.RxObserver;
import com.baseandroid.retrofit.json.Data;
import com.qianbao.qianbaobusiness.json.GStoreBean;
import com.qianbao.qianbaobusiness.json.UnPayShopListBean;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * @author: Routee
 * @date 2018/6/11
 * @mail wangc4@qianbaocard.com
 * ------------1.本类由Routee开发,阅读、修改时请勿随意修改代码排版格式后提交到git。
 * ------------2.阅读本类时，发现不合理请及时指正.
 * ------------3.如需在本类内部进行修改,请先联系Routee,若未经同意修改此类后造成损失本人概不负责。
 */
public class MinePresenter extends RxMvpPresenter<MineView> {
    ContractApi mApi;
    MyApi       myApi;

    @Inject
    public MinePresenter(ContractApi api, MyApi myApi) {
        mApi = api;
        this.myApi = myApi;
    }

    public void getGstoreList() {
        mApi.getGstoreList(Global.getUserInfoBean().getUser().getMobile()).compose(RxUtils.applySchedulersLifeCycle(getView()))
                .subscribe(new RxObserver<Data<List<GStoreBean.ResultBean>>>() {
                    @Override
                    public void onNext(Data<List<GStoreBean.ResultBean>> data) {
                        super.onNext(data);
                        getView().getGstoreListSuccess(data.getResult());
                        //getView().getGstoreListSuccess(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                });
    }

    /**
     * @param s
     */
    //    public void getMerchantDepositInfo(String s) {
    //        myApi.getMerchantDepositInfo(s)
    //                .compose(RxUtils.applySchedulersLifeCycle(getView()))
    //                .subscribe(new Observer<Data<MerchantsBean>>() {
    //                    @Override
    //                    public void onSubscribe(Disposable d) {
    //
    //                    }
    //
    //                    @Override
    //                    public void onNext(Data<MerchantsBean> merchantUnpayDepositInfoBeanData) {
    //                        if (RxObserver.checkJsonCode(merchantUnpayDepositInfoBeanData, false)) {
    //                            getView().getMerchantUnpaySuccess(merchantUnpayDepositInfoBeanData.getResult());
    //                        }
    //                    }
    //
    //                    @Override
    //                    public void onError(Throwable e) {
    //
    //                    }
    //
    //                    @Override
    //                    public void onComplete() {
    //
    //                    }
    //                });
    //    }
    public void getMerchantUnpayDepositInfo(String merchantNos) {
        myApi.getMerchantUnpayDepositInfo(merchantNos)
                .compose(RxUtils.applySchedulersLifeCycle(getView()))
                .subscribe(new Observer<Data<UnPayShopListBean>>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(Data<UnPayShopListBean> merchantUnpayDepositInfoBeanData) {
                        if (RxObserver.checkJsonCode(merchantUnpayDepositInfoBeanData, false)) {
                            getView().getMerchantUnpaySuccess(merchantUnpayDepositInfoBeanData.getResult());
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
